import { BaseObject } from './BaseObject'

/**
 * KeyValue
 * @author LL
 * @date 2022-01-23 上午 1:52
 **/
export class KeyValue<K = string, V = string> extends BaseObject {
    public key: K
    public value: V

    constructor(key: K, value: V) {
        super()
        this.key = key
        this.value = value
    }

    public override equals(o: any): boolean {
        if (super.equals(o)) {
            return true
        }
        if (!(o instanceof KeyValue)) {
            return false
        }
        return o.key === this.key && o.value === this.value
    }

    public override hashCode(): number {
        return super.hashCode()
    }

    public override toString(): string {
        return `${ this.key }=${ this.value }`
    }

    /**
     * toString 的 "重载"
     * 可以自定义分隔符 connect 默认 =
     * @param {string} connect
     * @return {string}
     */
    public toStr(connect: string = '=') {
        return `${ this.key }${ connect }${ this.value }`
    }
}
